<?php
namespace Bshop\Controller;
class ActivityController extends CkadminController {
    public function index($res=null){
    	$id = (int)I('get.id');
    	if($id){
    		$res = M('activity')->where("id='$id'")->find();
    	}
    	if(!empty($res)){
    		$res['body'] = str_replace('"',"'", $res['body']);
    		$res['cityname'] = R('Reuse/cityname',array('',$res['cityid']));
    		$res['areaname'] = R('Reuse/cityname',array('','',$res['areaid']));
    		$res['circlename'] = R('Reuse/circlename',array($res['circle_id']));
    		$res['photolist'] = explode(",",$res['photo']);//标签
    		//$res['labellist'] = explode(",",$res['label']);
    		if(!empty($res['label'])){
    			$data['id'] = array('in',$res['label']);
    			$labellist = M('label')->where($data)->field("id,name")->select();
    			$this->assign('labellist',$labellist);
    		}
    		//场次
    		if($id){
    			$res['information_title'] = json_decode($res['information_title'],true);
    			$res['field'] = M('activity_field')->where("aid ='$id'")->order("sort asc")->select();
    			if(!empty($res['field'])){
    				foreach ($res['field'] as $i=>$va){
    					if($res['time_type'] == 2 || $res['time_type'] == 4){
    						$res['field'][$i]['activity_week'] = explode(",",$va['activity_week']);
    					}
    					$res['field'][$i]['ticket'] = M('activity_ticket')->where("aid ='$id' and field_id='{$va['id']}'")->order("sort asc")->select();
    				}
    			}
    		}
    		if($_POST){
    			$res['information_title'] = array('information_title'=>$_POST['information_title'],'order_title'=>$_POST['orther_title'],'accessory_name'=>$_POST['accessory_name']);
    			$aid = $res['id']?$res['id']:$_POST['id'];
    			if(!empty($aid)){
    				$field_id = M('activity_field')->where("aid='{$aid}'")->field("id")->select();
    			}
    			list($res['east'],$res['north']) =  explode(",",$_POST['east']);
    			$res['circlename'] = R('Reuse/circlename',array($_POST['circle_id']));
    			$res['activity_start_date'] = $_POST['wai_activity_start_date'];
    			$res['activity_end_date'] = $_POST['wai_activity_end_date'];
    			$is_order = $_POST['is_order'];
    			//单个日期
    			if($_POST['time_type'] == 1){
    				$start_date = $_POST['activity_start_date'];
    				$activity_start_time = $_POST['activity_start_time'];
    				$activity_end_time = $_POST['activity_end_time'];
    				
    				foreach ($start_date as $i=>$va){
    					$res['field'][] = array(
    							'id' => $field_id[$i]['id'],
    							'activity_start_date'=>$va,
    							'activity_start_time'=>$activity_start_time[$i],
    							'activity_end_time'=>$activity_end_time[$i],
    							'is_order' => intval($is_order[$i]),
    					);
    				}
    					
    			}
    			//按周重复
    			elseif ($_POST['time_type'] == 2){
    				$start_date = $_POST['activity_start_date'];
    				$activity_end_date = $_POST['activity_end_date'];
    				$activity_start_time = $_POST['activity_start_time'];
    				$activity_end_time = $_POST['activity_end_time'];
    				foreach ($start_date as $i=>$va){
    					$res['field'][] = array(
    							'id' => $field_id[$i]['id'],
    							'activity_start_date'=>$va,
    							'activity_start_time'=>$activity_start_time[$i],
    							'activity_end_time'=>$activity_end_time[$i],
    							'activity_end_date' => $activity_end_date[$i],
    							'activity_week' => $_POST['week'.($i+1)],
    							'is_order' => intval($is_order[$i]),
    					);
    				}
    			}
    			//连续日期
    			elseif ($_POST['time_type'] == 3){
    				$start_date = $_POST['activity_start_date'];
    				$activity_end_date = $_POST['activity_end_date'];
    				$activity_start_time = $_POST['activity_start_time'];
    				$activity_end_time = $_POST['activity_end_time'];
    				foreach ($start_date as $i=>$va){
    					$res['field'][] = array(
    							'id' => $field_id[$i]['id'],
    							'activity_start_date'=>$va,
    							'activity_start_time'=>$activity_start_time[$i],
    							'activity_end_time'=>$activity_end_time[$i],
    							'activity_end_date' => $activity_end_date[$i],
    							'is_order' => intval($is_order[$i]),
    					);
    				}
    			}
    			//长期举办
    			else if($_POST['time_type'] == 4){
    				$activity_start_time = $_POST['activity_start_time'];
    				$activity_end_time = $_POST['activity_end_time'];
    				foreach ($activity_start_time as $i=>$va){
    					$res['field'][] = array(
    							'id' => $field_id[$i]['id'],
    							'activity_start_time'=>$activity_start_time[$i],
    							'activity_end_time'=>$activity_end_time[$i],
    							'activity_week' => $_POST['week'.($i+1)],
    							'is_order' => intval($is_order[$i]),
    					);
    				}
    			}else{
    				$res['field'] = array();
    			}
    			foreach ($res['field'] as $k=>$vv){
    				if(!empty($vv['id'])){
    					$card_id[$k] = M('activity_ticket')->where("field_id='{$vv['id']}'")->field("id")->select();
    				}
    				$ticket_name[$k] = $_POST['ticket_name'.($k+1)];
    				$true_price[$k] = $_POST['true_price'.($k+1)];
    				$old_price[$k] = $_POST['old_price'.($k+1)];
    				$number[$k] = $_POST['number'.($k+1)];
    				$ticket_limit[$k] = $_POST['ticket_limit'.($k+1)];
    				$ticket_explain[$k] = $_POST['ticket_explain'.($k+1)];
    				foreach ($ticket_name[$k] as $j=>$vj){
    					$res['field'][$k]['ticket'][] = array(
    							'id' => $card_id[$k][$j]['id'],
    							'ticket_name'=>$vj,
    							'true_price'=>$true_price[$k][$j],
    							'old_price'=>$old_price[$k][$j],
    							'old_price'=>$old_price[$k][$j],
    							'number'=>$number[$k][$j],
    							'ticket_limit'=>$ticket_limit[$k][$j],
    							'ticket_explain'=>$ticket_explain[$k][$j]
    					);
    				}
    			}
    		}
    			
    		$this->assign('va',$res);
    	}
    	//城市
    	$list = M('citys')->where("close = '1' and parent_id = '0'")->field("id,name")->select();
    	$this->assign('list',$list);
    	//活动分类
    	$classlist1 = M('activity_classify')->where("close = '1'")->field("id,name,parent_id")->select();
    	$classlist = \Org\Oa\common::sortdata($classlist1,0,'&nbsp;&nbsp;&nbsp;&nbsp;');
    	$this->assign('classlist',$classlist);
    	$this->display('Activity/index');
    }
    public function save_activity(){
    	$callback = $_POST['callback'];
    	$db = D('Activity');
    	if($create = $db->create()){
    		$id = (int)I('post.id');
    		//$create['close'] = 1;
    		$create['body'] = str_replace('"',"'",$_POST['body']);
    		$create['shop_id'] = $_SESSION['eventor_shop_user_id'];
    		$east = str_replace("，",',', $create['east']);
    		list($create['east'],$create['north']) = explode(",",$east);
    		$create['activity_start_date'] = $_POST['wai_activity_start_date'];
    		$create['activity_end_date'] = $_POST['wai_activity_end_date'];
    		if($create['fee_type'] == 3){
    			$create['time_type'] = 0;
    		}
    		$information_title = $_POST['information_title'];
    		$orther_name = $_POST['orther_title'];
    		$accessory_name = $_POST['accessory_name'];
    		$arr = array();
    		if(!empty($information_title[0])){
    			$arr['information_title'] = $information_title;
    		}
    		if(!empty($orther_name[0])){
    			$arr['order_title'] = $orther_name;
    		}
    		if(!empty($accessory_name[0])){
    			$arr['accessory_name'] = $accessory_name;
    		}
    		if(!empty($arr)){
    			$create['information_title'] = json_encode($arr);
    		}
    		if($id){
    			$close = $db->where("id='$id'")->getField('close');
    			if($close == 1 || $close == 3){
    				$this->index($_POST);
    				echo alert("保存失败,请重新保存",C('URL')."/Activity/activity_list");exit;
    			}
    			$res = $db->save($create);
    			$aid = $id;
    			$type = 1;
    		}else{
    			$res = $db->add($create);
    			$aid = $res ;
    			$type = 0;
    		}
    		if($create['fee_type'] == 1 || $create['fee_type'] ==2){
    			$this->add_changci($aid,$create['time_type'],$type);
    		}
    		$close = $db->where("id='{$aid}'")->getField('close');
    		if($close == 3){
    			$db->where("id='{$aid}'")->setField('close',0);
    		}
    		$this->index($_POST);
    		$url = $callback?"http://".$_SERVER['HTTP_HOST'].$callback:C('URL')."/Activity/activity_list";
    		if($id){
    			echo alert("添加保存成功",$url,1);
    		}else{
    			echo alert("添加保存成功",$url);
    		}
    		
    	}else{
    		$this->index($_POST);
    		echo showmsg($db->getError());exit;
    	}
    }
    /**
     * 删除活动
     */
    public function del_activity(){
    	if(IS_AJAX){
    		$id = (int)I('post.id');
    		$db = M('activity');
    		$re = $db->where("id='$id' and close !='1'")->delete();
    		if($re!=false){
    			M('activity_field')->where("aid = '$id'")->delete();
    			M('activity_ticket')->where("aid ='$id'")->delete();
    			echo jsonencode(200,"删除成功",C('URL')."/Activity/activity_list");
    		}else{
    			echo jsonencode(300,"删除失败");
    		}
    	}else{
    		echo jsonencode(300,"删除失败");
    	}
    }
    /**
     * 活动列表
     */
    public function activity_list(){
    	$parameter =  !empty($_POST)?$_POST:$_GET;
    	$url            =   U('',$parameter);
    	$this->url = $url;
    	$uid = $_SESSION['eventor_shop_user_id'];
    	//城市
    	$citys = M('citys')->where("close = '1' and parent_id = '0'")->field("id,name")->select();
    	$this->assign('city',$citys);
    	//商家分类
    	$classlist1 = M('activity_classify')->order("id desc")->field("id,name,parent_id")->select();
    	$classlist = \Org\Oa\common::sortdata($classlist1,0,'&nbsp;&nbsp;&nbsp;&nbsp;');
    	$this->assign('classlist',$classlist);
    	$name = I('name');
    	if(!empty($name)){
    		$where['name'] = array('like',"%{$name}%");
    	}
    	$close = (int)I('close');
    	$a = \Org\Web\activity::true_activity();//正常运行的活动
    	if($close == 1){
    		if(empty($a)){
    			exit;
    		}
    		$where['id'] = array('in',$a);
    	}elseif ($close == 2){
    		if(empty($a)){
    			exit();
    		}
    		$where['id'] = array('not in',$a);
    	}
    	$class_id = (int)I('class_id');
    	if(!empty($class_id)){
    		$three_class_id = \Org\Web\activity::class_activity($class_id);
    		$where['class_id'] = array('in',$three_class_id);
    	}
    	$fee_type = (int)I('fee_type');
    	if(!empty($fee_type)){
    		$where['fee_type'] = $fee_type;
    	}
    	$start_time = I('start_time')?I('start_time'):"1990-01-01";
    	$end_time = I('end_time')?I('end_time'):"2550-01-01";
    	$where['add_time'] = array('between',array($start_time,$end_time));
    	$where['shop_id'] = $uid;
    	//$common = new \Org\Oa\common();
    	$db = M('activity');
    	//$count = $db->where($where)->count();
    	//$page = new \Org\Oa\page($count,20);
    	//$show = $page->show();
    	$list = $db->where($where)->order("id desc")->limit($page->firstRow.",".$page->listRows)->select();
    	/* if(!empty($list)){
    		$db1 = M('activity_ticket');
    		$db2 = M('order');
    		foreach ($list as $i=>$va){
    			//库存
    			$list[$i]['count_ticket'] = $db1->where("aid ='{$va['id']}'")->sum('number');
    			if(empty($list[$i]['count_ticket'])){
    				$list[$i]['count_ticket'] = 0;
    			}
    			//已售
    			$list[$i]['yi_shou'] = $db2->where("aid='{$va['id']}' and pay_status ='1'")->sum('number');
    			if(empty($list[$i]['yi_shou'])){
    				$list[$i]['yi_shou'] = 0;
    			}
    		}
    	} */
    	$this->assign('list',$list);
    	$this->display();
    }
    /**
     * 票务管理
     */
    public function piao(){
    	$type = (int)I('post.type');
    	$order_no = I('order_no');
    	if(!empty($order_no)){
    		$where['o.order_no'] = array('like',"%{$order_no}%");
    	}
    	$name = I('name');
    	if(!empty($name)){
    		$where['a.name'] = array('like',"%{$name}%");
    	}
    	$shop_name = I('shop_name');
    	if(!empty($shop_name)){
    		$where['s.shop_name'] = array('like',"%{$shop_name}%");
    	}
    	$username = I('username');
    	if(!empty($username)){
    		$where['u.username'] = array('like',"%{$username}%");
    	}
    	$is_use = I('is_use');
    	if($is_use !=''){
    		$where['ot.is_use'] = $is_use;
    	}
    	$add_time = I('check_time');
    	if(!empty($add_time)){
    		$end_date = date("Y-m-d",strtotime("+ 1 day",strtotime($add_time)));
    		$where['ot.check_time'] = array('between',array($add_time,$end_date));
    	}
    	$where['o.pay_status'] = array('gt',0);
    	$where['o.shop_id'] = $_SESSION['eventor_shop_user_id'];
    	$db = M('order_ticket as ot');
    	$list = $db->join("left join ".C('DB_PREFIX')."order as o on ot.order_id = o.id left join ".C('DB_PREFIX')."user as u on o.uid = u.id left join ".C('DB_PREFIX')."activity as a on a.id = o.aid left join ".C('DB_PREFIX')."activity_ticket as t on t.id = ot.ticket_id left join ".C('DB_PREFIX')."shop as s on ot.shop_id = s.id")->where($where)->field('ot.id,ot.ticket_no,ot.check_time,ot.ticket_date,ot.order_id,ot.shop_id,ot.is_use,o.aid,o.uid,o.order_no,u.username,a.name,o.is_quit,t.ticket_name,t.true_price,s.shop_name,ot.is_clear,ot.clear_time')->order("ot.id desc")->select();
    	if(!empty($list)){
    			foreach ($list as $i=>$va){
    				if($type!='1'){
    					$a[$i] = \Org\Web\activity::ticket_is_out_date($va['order_id'], $va['ticket_no']);
    					if($a[$i]){
    						$list[$i]['is_use'] = 4;
    					}
    				}
    				if($va['is_use']!='1'){
    					$list[$i]['ticket_no'] = "";
    				}
    				if($va['true_price'] == '0.00'){
    					$list[$i]['true_price_name'] = "免费";
    				}else{
    					$list[$i]['true_price_name'] = $va['true_price'];
    				}
    				$list[$i]['is_use_name'] = \Org\Web\activity::ticket_status($list[$i]['is_use']);
    				if($va['is_quit'] == '1' and $va['true_price'] != '0.00'){
    					$list[$i]['is_quit_name'] = "可退";
    				}else{
    					$list[$i]['is_quit_name'] = "不可退";
    				}
    				if($va['is_clear'] == 0){
    					$list[$i]['over_time_name'] = "--";
    				}elseif ($va['is_clear'] == 1){
    					$list[$i]['over_time_name'] = $va['clear_time'];
    				}elseif ($va['is_clear'] == 2){
    					$list[$i]['over_time_name'] ="等待审核";
    				}
    				
    			}
    	}
    	if($type == 1){
    		$fileName = "票务管理";
    		$this->getExcel($fileName, $list);exit;
    	}
    	$this->assign('list',$list);
    	$this->display();
    }
  
    private  function getExcel($fileName,$data){
    	//导入PHPExcel类库，因为PHPExcel没有用命名空间，只能inport导入
    	import("Org.Util.PHPExcel");
    	import("Org.Util.PHPExcel.Writer.Excel5");
    	import("Org.Util.PHPExcel.IOFactory.php");
    	import("Org.Util.PHPExcel.style.Alignment.php");
    	$date = date("Y_m_d",time());
    	$fileName .= "_{$date}.xls";
    
    	//创建PHPExcel对象，注意，不能少了\
    	$objPHPExcel = new \PHPExcel();
    	$objProps = $objPHPExcel->getProperties();
    	$objPHPExcel->setActiveSheetIndex(0)
    	//设置表的名称标题
    	->setCellValue('A1',"序号")
    	->setCellValue('B1',"订单")
    	->setCellValue('C1',"票号")
    	->setCellValue('D1',"订票人")
    	->setCellValue('E1',"活动名称")
    	->setCellValue('F1',"场次时间")
    	->setCellValue('G1',"金额")
    	->setCellValue('H1',"状态")
    	->setCellValue('I1',"是否可退")
    	->setCellValue('J1',"结算时间");
        foreach($data as $k=>$v){
			$num = $k+2;
			$objPHPExcel->setActiveSheetIndex(0)
			//Excel的第A列，uid是你查出数组的键值，下面以此类推
			->setCellValue('A'.$num, $v["id"])
			->setCellValue('B'.$num, $v["order_no"])
			->setCellValue('C'.$num, $v["ticket_no"])
			->setCellValue('D'.$num, $v["username"])
			->setCellValue('E'.$num, $v['name'])
			->setCellValue('F'.$num, $v['ticket_date'])
			->setCellValue('G'.$num, $v['true_price_name'])
			->setCellValue('H'.$num, $v['is_use_name'])
			->setCellValue('I'.$num, $v['is_quit_name'])
			->setCellValue('J'.$num, $v['over_time_name']);
		}
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(24);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(24);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(24);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(24);
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
		$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(24);
		$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(24);
		$objPHPExcel->getActiveSheet()->getStyle('A1:N'.($num))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    	$fileName = iconv("utf-8", "gb2312", $fileName);
       
    	//重命名表
    	//$objPHPExcel->getActiveSheet()->setTitle('test');
    	//设置活动单指数到第一个表,所以Excel打开这是第一个表
    	$objPHPExcel->setActiveSheetIndex(0);
    	ob_end_clean();//清除缓冲区,避免乱码
    	header('Content-Type: application/vnd.ms-excel');
    	header("Content-Disposition: attachment;filename=\"$fileName\"");
    	header('Cache-Control: max-age=0');
    
    	$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    	$objWriter->save('php://output'); //文件通过浏览器下载
    	exit;
    }
    private function add_changci($aid,$type,$method){
		$db = M('activity_field');
		$activity_start_date = $_POST['activity_start_date'];
		$activity_end_date = $_POST['activity_end_date'];
		$activity_start_time = $_POST['activity_start_time'];
		$activity_end_time = $_POST['activity_end_time'];
		$field_id = $_POST['field_id'];
		$is_order = $_POST['is_order'];
		if(!empty($method)){
			if(!empty($field_id[0])){
				$db1 = M('activity_ticket');
				$re = $db->where("aid='{$aid}'")->field("id")->select();
				foreach ($re as $b=>$vl){
					if(in_array($vl['id'],$field_id)){
					}else{
						$db->where("id='{$vl['id']}'")->delete();
						$db1->where("field_id='{$vl['id']}'")->delete();
					}
				}
			}
		}
		if($type == 1){
			//单个日期
			foreach ($activity_start_date as $i=>$va){
				if(!empty($va)){
					$data['activity_start_date'] = $va;
					$data['activity_end_date'] = $va;
					$data['activity_start_time'] = $activity_start_time[$i];
					$data['activity_end_time'] = $activity_end_time[$i];
					$data['aid'] = $aid;
					$data['sort'] = $i;
					$data['is_order'] = intval($is_order[$i]);
					if($field_id[$i]){
						$data['id'] = $field_id[$i];
						$db->save($data);
					}else{
						$data['id'] = $this->parekey('activity_field');
						$db->add($data);
					}
					$id = $data['id'];
					$this->add_tickte($aid,$id,$method,$i+1);
				}
			} 
		}elseif ($type == 2){
			//按周重复
			foreach ($activity_start_date as $i=>$va){
				if(!empty($va)){
					$data['activity_start_date'] = $va;
					$data['activity_start_time'] = $activity_start_time[$i];
					$data['activity_end_time'] = $activity_end_time[$i];
					$data['activity_end_date'] = $activity_end_date[$i];
					$data['activity_week'] = join(",",$_POST['week'.($i+1)]);
					$data['aid'] = $aid;
					$data['sort'] = $i;
					$data['is_order'] = intval($is_order[$i]);
					if($field_id[$i]){
						$data['id'] = $field_id[$i];
						$db->save($data);
					}else{
						$data['id'] = $this->parekey('activity_field');
						$db->add($data);
					}
					$id = $data['id'];
					$this->add_tickte($aid,$id,$method,$i+1);
				}
			}
		}elseif ($type == 3){
			//连续日期
			foreach ($activity_start_date as $i=>$va){
				if(!empty($va)){
					$data['activity_start_date'] = $va;
					$data['activity_start_time'] = $activity_start_time[$i];
					$data['activity_end_time'] = $activity_end_time[$i];
					$data['activity_end_date'] = $activity_end_date[$i];
					$data['aid'] = $aid;
					$data['sort'] = $i;
					$data['is_order'] = intval($is_order[$i]);
					if($field_id[$i]){
						$data['id'] = $field_id[$i];
						$db->save($data);
					}else{
						$data['id'] = $this->parekey('activity_field');
						$db->add($data);
					}
					$id = $data['id'];
					$this->add_tickte($aid,$id,$method,$i+1);
				}
				
			}
		}elseif ($type == 4){
			//长期举办
			foreach ($activity_start_time as $i=>$va){
				if(!empty($va)){
					$data['activity_start_time'] = $va;
					$data['activity_end_time'] = $activity_end_time[$i];
					$data['activity_week'] = join(",",$_POST['week'.($i+1)]);
					$data['activity_end_date'] = "2550-01-01";
					$data['activity_start_date'] = date("Y-m-d");
					$data['aid'] = $aid;
					$data['sort'] = $i;
					$data['is_order'] = intval($is_order[$i]);
					if($field_id[$i]){
						$data['id'] = $field_id[$i];
						$db->save($data);
					}else{
						$data['id'] = $this->parekey('activity_field');
						$db->add($data);
					}
					$id = $data['id'];
					$this->add_tickte($aid,$id,$method,$i+1);
				}
			}
		}
		
	}
    /**
     * 增加、编辑票价
     */
    private function add_tickte($aid,$field_id,$method,$i){
		$ticket_name = $_POST['ticket_name'.$i];
		$true_price = $_POST['true_price'.$i];
		$old_price = $_POST['old_price'.$i];
		$number = $_POST['number'.$i];	
		$ticket_limit = $_POST['ticket_limit'.$i];
		$ticket_explain = $_POST['ticket_explain'.$i];
		$ticket_id = $_POST['ticket_id'.$i];
		$db1 = M('activity_ticket');
		if(!empty($method)){
			if(!empty($ticket_id[0])){
				$re=$db1->where("field_id='$field_id'")->field("id")->select();
				foreach ($re as $l=>$vl){
					if(in_array($vl['id'],$ticket_id)){
				
					}else{
						$db1->where("id='{$vl['id']}'")->delete();
					}
				}
			}
		}
		foreach ($ticket_name as $k=>$vv){
			if(!empty($vv)){
				$map['ticket_name'] = $vv;
				$map['aid'] = $aid;
				$map['field_id'] = $field_id;
				$map['true_price'] = $true_price[$k];
				$map['old_price'] = $old_price[$k];
				$map['number'] = $number[$k];
				$map['ticket_limit'] = $ticket_limit[$k];
				$map['ticket_explain'] = $ticket_explain[$k];
				$map['sort'] = $k;
				if($ticket_id[$k]){
					$map['id'] = $ticket_id[$k];
					$db1->save($map);
				}else{
					$map['id'] = $this->parekey('activity_ticket');
					$db1->add($map);
				}
			}
			
		}
	}
	/**
	 * 保存预览
	 */
	public function save_yulan_activity(){
		$db = D('Activity');
		if($create = $db->create()){
			$create['close'] = 4;
			$id = (int)I('post.id');
			$body = str_replace('"',"'",$_POST['body']);
			$create['body'] = $body;
			$east = str_replace("，",',', $create['east']);
			list($create['east'],$create['north']) = explode(",", $east);
			if($id){
				$res = $db->save($create);
				$aid = $id;
				$type = 1;
			}else{
				$res = $db->add($create);
				$aid = $res ;
				$type = 0;
			}
			if($create['fee_type'] == 1 || $create['fee_type'] ==2){
				$this->add_changci($aid,$create['time_type'],$type);
			}
			$create['id'] = $aid;
			$this->index($create);
			echo '<script>lookyixia('.$aid.')</script>';exit();
		}else{
			$this->index($_POST);
			echo showmsg($db->getError());exit;
		}
	}
}